#include <iostream>
#include <iomanip>
#include "diamond.h"

using namespace std;

Diamond::Diamond( int nstar ) {
    setStars(nstar);
}

void Diamond::setStars( int nstar ) {
    Stars = nstar > 0 ? nstar : 10;
    Stars += (Stars % 2 ? 0 : 1);//make sure stars is an odd
}

int Diamond::getStars() const {
    return Stars;
}

void Diamond::display() const {
    this->print(cout);
}

void Diamond::print(ostream & out) const {
    int i = 1, step = 1;
    while (1) {
        if ( i == (Stars + 1)/2 ) step = -1;
        int stars = 2*i -1; 
        int spaces = (Stars - stars)/2;
        out.fill(' ');
        out << setw(spaces) << "";
        out.fill('*');
        out << setw(stars) << "";
        out.fill(' ');
        out << setw(spaces) << "" << endl;
        if ((i += step) == 0) break;;
    }
}

ostream & operator << (ostream & out, const Diamond & ndia){
    ndia.print( out );
    return out;
}
